home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Report Writers / Crystal Repot 9.0 Full CD version / Setup.exe / SRC / HOARDDLL.ZIP / 3rdParty / hoard / libhoard-2.0.2 / testmymalloc.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-03-15  |  1.8 KB  |  77 lines

  1. ///-*-C++-*-//////////////////////////////////////////////////////////////////
  2. //
  3. // Hoard: A Fast, Scalable, and Memory-Efficient Allocator
  4. //        for Shared-Memory Multiprocessors
  5. // Contact author: Emery Berger, http://www.cs.utexas.edu/users/emery
  6. //
  7. // Copyright (c) 1998-2000, The University of Texas at Austin.
  8. //
  9. // This library is free software; you can redistribute it and/or modify
  10. // it under the terms of the GNU Library General Public License as
  11. // published by the Free Software Foundation, http://www.fsf.org.
  12. //
  13. // This library is distributed in the hope that it will be useful, but
  14. // WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. // Library General Public License for more details.
  17. //
  18. //////////////////////////////////////////////////////////////////////////////
  19.  
  20. #include <assert.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23.  
  24. #include "timer.h"
  25.  
  26. class Foo {
  27. public:
  28.   Foo (void)
  29.     : x (143.0)
  30.     {}
  31.  
  32.   double x;
  33. };
  34.  
  35.  
  36. int main (int argc, char * argv[])
  37. {
  38.   int iterations;
  39.   int size;
  40.  
  41.   if (argc > 2) {
  42.     iterations = atoi(argv[1]);
  43.     size = atoi(argv[2]);
  44.   } else {
  45.     fprintf (stderr, "Usage: %s iterations size\n", argv[0]);
  46.     exit(1);
  47.   }
  48.  
  49.   Timer t1, t2;
  50.  
  51.   long int i, j;
  52.   Foo ** a;
  53.   a = new Foo * [iterations];
  54.  
  55.   for (int n = 0; n < 1; n++) {
  56.     t1.start ();
  57.     for (i = 0; i < iterations; i++) {
  58.       a[i] = new Foo[size];
  59.     }
  60.     t1.stop ();
  61.     
  62.     t2.start ();
  63.     for (j = iterations - 1; j >= 0; j--) {
  64.       delete a[j];
  65.     }
  66.     t2.stop ();
  67.   }
  68.  
  69.   delete [] a;
  70.  
  71.   printf( "Alloc: %f\n", (double) t1);
  72.   printf("free: %f\n", (double) t2);
  73.   printf("total: %f\n", (double) t1 + (double) t2);
  74.  
  75.   return 0;
  76. }
  77.